package com.guanglan.serviceImpl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.guanglan.dao.SysPermissionMapper;
import com.guanglan.dao.SysRolePermissionMapper;
import com.guanglan.domain.SysPermission;
import com.guanglan.service.SysPermissionService;

/**
 * 
 * @author guanglan
 *
 */
@Service
public class SysPermissionServiceImpl implements SysPermissionService {
	
	@Autowired
	private SysPermissionMapper permissionMapper;
	@Autowired
	private SysRolePermissionMapper sysRolePermissionMapper;
	

	@Transactional
	public int deleteByPrimaryKey(Long id) {
		int count = permissionMapper.deleteByPrimaryKey(id);
		List<SysPermission> list = permissionMapper.getAllParentPerm();
		list.forEach(s -> {
			permissionMapper.deleteChildNode(s.getId());
		});
		sysRolePermissionMapper.deleteByPid(id);
		return count;
	}

	public int insert(SysPermission record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int insertSelective(SysPermission record) {
		// TODO Auto-generated method stub
		return permissionMapper.insertSelective(record);
	}

	public SysPermission selectByPrimaryKey(Long id) {
		// TODO Auto-generated method stub
		return null;
	}

	public int updateByPrimaryKeySelective(SysPermission record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public int updateByPrimaryKey(SysPermission record) {
		// TODO Auto-generated method stub
		return 0;
	}

	public List<SysPermission> selectByPermissionId(List<Long> list) {
		// TODO Auto-generated method stub
		return permissionMapper.selectByPermissionId(list);
	}

	@Override
	public List<SysPermission> getSysPermissions(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return permissionMapper.getSysPermissions(params);
	}

	@Override
	public Integer getSysPermissionsCount(Map<String, Object> params) {
		// TODO Auto-generated method stub
		return permissionMapper.getSysPermissionsCount(params);
	}

	@Override
	public List<SysPermission> getAllParentPerm() {
		// TODO Auto-generated method stub
		return permissionMapper.getAllParentPerm();
	}

}
